<template>

      <!-- 顶部导航栏 -->
  <el-container>
      <el-header>
        <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            :ellipsis="false"
            @select="handleSelect"
        >
          <el-menu-item index="0">
            <img
                style="width: 100%;height: 100%"
                src="http://localhost:8080/image/upload/1718597558435.png"
                alt="Element logo"
            />
          </el-menu-item>
          <div class="flex-grow" />
          <el-menu-item index="1">欢迎您,{{this.userinfo.user_name}}<el-icon><UserFilled/></el-icon></el-menu-item>
          <el-menu-item index="2">
            <el-button type="primary" round @click="ExitLogin">退出登录</el-button>
          </el-menu-item>
        </el-menu>
      </el-header>
  </el-container>
  <el-container>
    <!-- 左边导航栏 -->
      <el-aside width="150px">
        <el-menu
            default-active=''
            class="el-menu-vertical-demo"
            router
        >
          <el-menu-item v-for="item in menuList" :index="item.path">
            <el-icon><icon-menu /></el-icon>
            <span>{{item.meta.title}}</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
    <!-- 展示的内容：右边  -->
      <el-main>
        <router-view></router-view>
      </el-main>
  </el-container>
</template>

<script>
import {useRouter} from "vue-router"
import {UserFilled} from "@element-plus/icons-vue";
export default {
  components: {UserFilled},
  data(){
    return{
      userinfo:{
      user_name:'',
      user_id:''
      },
      key:'',
      keyPath:[],
      router:useRouter(),
      activeIndex:1,
      menuList:[]
    }
  },
  methods:{
    LoadUserData(){
      this.user_id=localStorage.getItem('user_id')
      console.log(this.user_id)
      this.$http.get("http://localhost:8080/user/showdetailuserinfo",{params:{
          user_id:this.user_id
        }}).then((res)=>{
        this.userinfo=res.data
        console.log(this.userinfo)
      }).catch(function(err){
        console.log(err);
      })
    },
    handleSelect(key,keypath){
      console.log(key, keyPath)
    },
    ExitLogin(){
      this.router.push('/');
    }
  },
  mounted(){
    // 获取路由信息并根据路由的meta字段中的power属性值为20筛选出符合条件的路由信息
    const myrouter = this.router.getRoutes();
    //获取当前页面中的路由信息，将路由信息存储在变量myrouter中
    this.menuList = myrouter.filter(item=>item.meta.power===20)
    //对获取到的路由信息进行筛选，将符合条件（即meta字段中的power属性值为20）的路由信息筛选出来，然后存储在变量menuList中
    console.log(myrouter);
    // 得到要显示的数据
    console.log(this.menuList);
    this.LoadUserData();
  }
}
</script>

<style>
.flex-grow {
  flex-grow:1;
}
</style>